'''
Created on 01-12-2012

@author: Maryla
'''
from Info import VMInfo
from Logger import logger  
from Consts import CONST

class VMMonitoring:
    
    def __init__(self):
        self.machineStatuses = {
                0: 'null',
                1: 'powered off',
                2: 'saved',
                3: 'teleported',
                4: 'aborted',
                5: 'running',
                6: 'paused',
                7: 'stuck',
                8: 'teleporting',
                9: 'live snapshotting',
                10: 'starting',
                11: 'stopping',
                12: 'saving',
                13: 'restoring'
                 }
        
    
    def gatherVMStats(self, nameOrId, vmInfo=None):
        if(vmInfo==None):
            vmInfo=VMInfo()
        foundedVm = vmInfo.findMachine(nameOrId)
        stats={}
        if(foundedVm != None):
            stats[CONST.name] = foundedVm.name
            stats[CONST.id] = foundedVm.id
            stats[CONST.cpucount] = foundedVm.CPUCount
            stats[CONST.memsize] = foundedVm.memorySize
            stats[CONST.vramsize] = foundedVm.VRAMSize
            stats[CONST.status] = self.machineStatuses[foundedVm.state]
       
        logger.info(stats)
        
        return stats

if __name__ == "__main__":
        mon = VMMonitoring()
        stats = mon.gatherVMStats("fedora")
        print stats
        
    